/**
 * Created by sakuri on 2017/4/12
 */
;-function (window) {
    "use strict";
    //预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        right_chart_tab_1: null,
        right_chart_tab_2: null,
        index_court: null,
        // judge: [],
        judge_name: [],
        courtrooms: [],
        courtrooms_name: [],
        video_urls:null,
        status_value:0,//记录当前选择的左侧标签
        count_start_time:null,//记录案件查询时查询总数的时间段
        count_end_time:null,
        pro_bar:progress.init('#pro_bar',{})
    };
    //初始化的方法写这里面
    var init = function () {
        Class.draw();//绘制页面
        init_ready();
        // init_ready();//加载预设变量
        Class.init_total();//初始化顶部统计栏
        Class.init_case_today(r.user_uuid);//初始化左侧列表信息
        Class.init_count_time();//时间统计
        Class.init_judge_ranking();//排名统计
        init_event();
        // Class.select_judge_group();//初始化左侧列表数据
        function init_event() {
            //初始化页面事件
            $('#right_chart_tab_2_li').click(function () {
                console.log(ready.right_chart_tab_width, ready.right_chart_tab_height);
                var opt = {
                    width: ready.right_chart_tab_width,
                    height: ready.right_chart_tab_height,
                    silent: false
                };
                ready.right_chart_tab_2.resize(opt);
            });
            //时间插件预设为今年
            $('#startTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                console.log(ev.date.valueOf());
            });
            $('#endTime').datetimepicker({
                bootcssVer: 3,
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                weekStart: "1",
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                language: 'zh-CN', //汉化
                autoclose: true //选择日期后自动关闭
            }).on('changeDate', function (ev) {
                console.log(ev.date.valueOf());
            });

            $("#endTime").find("input").val(utils.get_date(0));
            $("#startTime").find("input").val(new Date().getFullYear()+"-01-01");
            $('.group-title-user-name').find('span').eq(1).html(r.user_name);
            var court = base.get_court(r.court_id);
            $('.group-title-user-court').find('span').eq(1).html(court.shortname);
            //初始化加载右侧表格
            Class.init_judge_count();
            //核查统计
            Class.init_verify_count();
            //搜索按钮
            $("#submitButton").click(function(){
                Class.init_judge_count();
                Class.init_verify_count();
            });

            $(window).resize(function () {
                Class.draw();
            });
        }
        function init_ready() {//初始化预设值
            ready.right_chart_tab_2 = echarts.init(document.getElementById('right-chart-tab-2'), "macarons");
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height=$('#right-chart-tab-1').height();
        }

    };

    //内部调用的方法写这里
    var Class = {
        draw: function () {
            //随着窗口大小改变 动态计算布局
            //设置第一块高度
            var window_height = $(window).height();
            var index_left_height = window_height - 280;
            $('#cmp-left-tabs-content').css('height', index_left_height + 'px');
            //设置第一块内元素边距
            var left_tab = ['left-tab-1', 'left-tab-2', 'left-tab-3'];
            $(left_tab).each(function (index, tab_id) {
                var tab = $('#' + tab_id);
                var tabs_li = tab.find('.media-list li');//获取所有条目
                var tabs_li_height = (index_left_height - 44) / 5;//计算每条所占大小
                if (tabs_li_height > 180) {//实际高度不能超过 180
                    tabs_li_height = 180;
                }
                tabs_li.css('height', tabs_li_height + 'px');//设置条目高度
                tabs_li.find('.cmp-left-media-item').css('margin-top', ((tabs_li_height - 30 - 100 ) / 2) + 'px');//每条目所占高度减去实际高度 等于边距高度
            });
            $('.media-list-with-divider').css('height', index_left_height - 40 + 'px');

            var left_img_width = $('.cmp-left-media-item img').actual('width');
            if (left_img_width >= 215) {
                var left_item_width = $('.cmp-left-media-item').actual('width');
                $('.cmp-left-media-item-content').css('width', left_item_width - 263 + 'px');
            }
            //设置第二块高度
            var index_center_height = window_height - 748;
            var cmp_center_panel = $('#cmp-center-tabs-content');
            cmp_center_panel.css('height', index_center_height + 'px');
            //设置第三块高度
            var index_right_height = window_height - 226;
            $('#cmp-right').css('height', index_right_height + 'px');
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height=$('#right-chart-tab-1').height();
        },

        init_total: function () {//TODO 顶部栏需要修改
            var anime = show_anime(50);
            $.get(r.base_path + 'judgeStatistical', {
                // courtId: r.court_id
                userIds:[r.user_uuid]
            }, function (result) {
                if (result.status == 0 && result.data) {
                    setTimeout(function () {
                        anime.close();
                        show(result.data);
                    }, 1000);//1秒后加载 后续优化可以去除
                }

            }, 'JSON');
            $.get(r.base_path+'getJudgeOpeningCourtNumRanking',{//法官开庭数排名
                courtId:r.court_id
            },function (result) {
                if (result.status==0) {
                    if ( result.data.length > 0 ){
                        if ( result.data.indexOf(r.user_uuid)> -1 ) {   //返回大于等于0的整数值，若不包含"字符串"则返回"-1。)
                            for (var i = 0; i < result.data.length; i++) {
                                if (result.data[i].user_id == r.user_uuid) {
                                    show_num_ranking( result.data[i].rownum);
                                }
                            }
                        }else{  //如果没有查出对应的法官记录排最后一名
                            show_num_ranking( result.data[result.data.length-1].rownum);
                        }
                    } else {
                        show_num_ranking(1);
                    }
                }
            });
            $.get(r.base_path+'getJudgeOpeningCourtTimeRanking',{//法官开庭时长排名
                courtId:r.court_id
            },function (result) {
                if (result.status==0) {
                    if ( result.data.length > 0 ){
                        if ( result.data.indexOf(r.user_uuid)> -1 ) {
                            for (var i = 0; i < result.data.length; i++) {
                                if (result.data[i].user_id == r.user_uuid) {
                                    show_time_ranking( result.data[i].rownum);
                                }
                            }
                        }else{
                            show_time_ranking( result.data[result.data.length-1].rownum);
                        }
                    } else {
                        show_time_ranking(1);
                    }
                }
            });
            function show_num_ranking(rownum) {
                var num_ranking = $('#num-ranking span');
                var rownums =format(rownum);
                num_ranking.eq(0).html(rownums[0]);
                num_ranking.eq(1).html(rownums[1]);
                num_ranking.eq(2).html(rownums[2]);
                num_ranking.eq(3).html(rownums[3]);
            }
            function show_time_ranking(rownum) {
                var num_ranking = $('#time-ranking span');
                var rownums =format(rownum);
                num_ranking.eq(0).html(rownums[0]);
                num_ranking.eq(1).html(rownums[1]);
                num_ranking.eq(2).html(rownums[2]);
                num_ranking.eq(3).html(rownums[3]);
            }
            function show(data) {
                //总容量
                var file_size_total = parseInt(data.judgeFileSize / 1048576);//这里单位是M 需要转换成T
                var file_size_total_arr = format(file_size_total);
                var cmp_plugins_title_size_span = $('.cmp-plugins-title-size span');
                cmp_plugins_title_size_span.eq(0).html(file_size_total_arr[0]);
                cmp_plugins_title_size_span.eq(1).html(file_size_total_arr[1]);
                cmp_plugins_title_size_span.eq(2).html(file_size_total_arr[2]);
                cmp_plugins_title_size_span.eq(3).html(file_size_total_arr[3]);
                //闭庭数
                // var closed_court_total_arr = format(data.judgeNumber);
                // var cmp_plugins_title_closed_span = $('.cmp-plugins-title-closed span');
                // cmp_plugins_title_closed_span.eq(0).html(closed_court_total_arr[0]);
                // cmp_plugins_title_closed_span.eq(1).html(closed_court_total_arr[1]);
                // cmp_plugins_title_closed_span.eq(2).html(closed_court_total_arr[2]);
                // cmp_plugins_title_closed_span.eq(3).html(closed_court_total_arr[3]);
                //开庭数
                var open_court_time_total_arr = format(data.judgeNumber);
                var cmp_plugins_title_open_court = $('.cmp-plugins-title-closed span');
                cmp_plugins_title_open_court.eq(0).html(open_court_time_total_arr[0]);
                cmp_plugins_title_open_court.eq(1).html(open_court_time_total_arr[1]);
                cmp_plugins_title_open_court.eq(2).html(open_court_time_total_arr[2]);
                cmp_plugins_title_open_court.eq(3).html(open_court_time_total_arr[3]);
                //法庭总数
                // var court_room_total_arr = format(data.courtRoomTotal);
                // var cmp_plugins_title_court = $('.cmp-plugins-title-court span');
                // cmp_plugins_title_court.eq(0).html(court_room_total_arr[0]);
                // cmp_plugins_title_court.eq(1).html(court_room_total_arr[1]);
                // cmp_plugins_title_court.eq(2).html(court_room_total_arr[2]);
                // cmp_plugins_title_court.eq(3).html(court_room_total_arr[3]);
                //科技法庭数
                // var technology_court_total_arr = format(data.technologyCourtTotal);
                // var cmp_plugins_title_technology = $('.cmp-plugins-title-technology span');
                // cmp_plugins_title_technology.eq(0).html(technology_court_total_arr[0]);
                // cmp_plugins_title_technology.eq(1).html(technology_court_total_arr[1]);
                // cmp_plugins_title_technology.eq(2).html(technology_court_total_arr[2]);
                // cmp_plugins_title_technology.eq(3).html(technology_court_total_arr[3]);
                // //总时长
                var count_court_now_total_arr = format(Math.round(data.judgeOpenTime / 24));
                var cmp_plugins_title_now = $('.cmp-plugins-title-now span');
                cmp_plugins_title_now.eq(0).html(count_court_now_total_arr[0]);
                cmp_plugins_title_now.eq(1).html(count_court_now_total_arr[1]);
                cmp_plugins_title_now.eq(2).html(count_court_now_total_arr[2]);
                cmp_plugins_title_now.eq(3).html(count_court_now_total_arr[3]);
            }

            function show_anime(delaytime) {
                if (!delaytime) {
                    delaytime = 100;
                }
                var anime_it = setInterval(function () {
                    var data = {};
                    data.fileSizeTotal = get_random_arr() * 1024 * 1024;
                    data.closedCourtTotal = get_random_arr();
                    data.openCourtTimeTotal = get_random_arr();
                    data.courtRoomTotal = get_random_arr();
                    data.technologyCourtTotal = get_random_arr();
                    data.countCourtNowTotal = get_random_arr();
                    show(data);
                }, delaytime);
                return {
                    close: function () {
                        clearInterval(anime_it);
                    }
                };
                function get_random_arr() {
                    return Math.floor(Math.random() * 10000);
                }
            }

            /**
             * 将数据拆分，转换成4位字符串数组，不足补0。
             * @param num 需要转换的数据
             * @return [*] 4位字符数组
             */
            function format(num) {
                var result_arr = ['0', '0', '0', '0'];
                if (!num) {
                    return result_arr;
                }
                num = num + '';
                var num_arr = num.split('');
                for (var i = 3, j = 3; i > -1; i--) {
                    if (num_arr[i]) {
                        result_arr[j] = num_arr[i];
                        j--;
                    }
                }
                return result_arr;
            }
        },
        init_case_today: function (judge) {
            judge =judge.toString();
            $.post(r.base_path + 'findJudgeCaseScheduleList', {
                // startDate: utils.get_date(0),
                courtId: r.court_id,
                judgeList: judge,
                page: 1,
                pageSize: 5
            }, function (result) {
                if (result && result.status == 0) {
                    if (result.data == null) {
                        // $('#left-tab-1').find('ul').html()
                        return;
                    }
                    var left_tab_1 = $('#left-tab-1');
                    left_tab_1.find('.media-list').empty();
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.start_date.substring(0, elem.start_date.length - 5);
                        var uri = encodeURI(r.base_path + "views/judge/living.html?uid=" + elem.uid);
                        left_tab_1.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<span class="cmp-left-media-item-status">' + elem.statusName + '</span>' +
                            '<img src="'+r.base_path+'assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    left_tab_1.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/judge/more_courting.html");
                    Class.draw();
                }
            }, 'json');
            $.post(r.base_path + 'findJudgeCaseReviewList', {
                courtId: r.court_id,
                judgeList: judge,
                // courtRoom: court_room,
                start: 0,
                pageSize: 5
            }, function (result) {
                var left_tab_2 = $('#left-tab-2');
                left_tab_2.find('.media-list').empty();
                if (result && result.status == 0) {
                    if (result.data == null) {
                        console.log('无开庭')
                    }
                }
                $(result.data).each(function (index, elem) {
                    var startDate = elem.start_date.substring(0, elem.start_date.length - 2);
                    var uri = encodeURI(r.base_path + "views/judge/play.html?planId=" + elem.uid);
                    left_tab_2.find('.media-list').append('<li class="media media-lg">' +
                        '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                        '<div class="cmp-left-media-item-img">' +
                        '<img src="'+r.base_path+'assets/img/list_test2.jpg"/>' +
                        '</div>' +
                        '<div class="cmp-left-media-item-content">' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p">' +
                        '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                        '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                        '</p>' +
                        '</div>' +
                        '</div></a>' +
                        '</li>');
                });
                left_tab_2.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/judge/more_reviewing.html");
                Class.draw();
            }, 'json').fail(function () {

            });
        },
        init_judge_count: function () {
            //获取时间
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            ready.count_start_time = start_time;
            ready.count_end_time = end_time;
            //获取案号
            var case_no = $("#caseno").val();
            //获取当前是排期或者回顾
            var status_tab = $(".cmp-left-tabs").find(".active").find("a").html();
            if("庭审排期" == status_tab){
                ready.status_value = "0";
            }else if("庭审回顾" == status_tab){
                ready.status_value = "1";
            }else{
                ready.status_value = "2";
            }

            if(ready.status_value == "2"){
                $("#right-list-tab-1").html("");
                $("#right-list-tab-1").append('<span>暂无数据</span>')
            }else{
                $.get(r.base_path + 'findListJudgeScheduleOrReviewCountCase', {
                    judgeList:r.user_uuid.toString(),
                    courtId: r.court_id,
                    // courtRoomId:temp_courtroom,
                    startDate:start_time,
                    endDate:end_time,
                    caseno:case_no,
                    status:ready.status_value
                }, function (result) {
                    if(result.status == 1){
                        $("#right-list-tab-1").html("");
                        $("#right-list-tab-1").append('<span>无数据</span>');
                        return;
                    }
                    $("#right-list-tab-1").html("");

                    $("#right-list-tab-1").append('<table id="table" class="table table-bordered context-span context-white cursor-hand"></table>');
                    $("#right-list-tab-1").append('<div id="_page"></div>');

                    var sum = result.data;
                    if (sum == 0) {
                        page(1, 1, null);
                    } else {
                        page(1, Math.ceil(sum / 5), Class.init_judge_detail);
                    }
                    Class.init_judge_detail(1);
                }, 'json').fail(function () {
                    alert("查询失败");
                });
            }

        },
        init_judge_detail: function (Index) {
            //获取时间
            var end_time = ready.count_end_time;
            var start_time = ready.count_start_time;
            //获取案号
            var case_no = $("#caseno").val();
            if(ready.status_value == "2"){
                $("#right-list-tab-1").html("");
                $("#right-list-tab-1").append('<span>暂无数据</span>')
            }else{
                $.get(r.base_path + 'findListJudgeScheduleOrReviewCase', {
                    judgeList:r.user_uuid.toString(),
                    courtId: r.court_id,
                    // courtRoomId:temp_courtroom,
                    startDate:start_time,
                    endDate:end_time,
                    caseno:case_no,
                    status:ready.status_value,
                    page:Index,
                    pageSize:5
                }, function (result) {
                    $('#table').bootstrapTable({
//			    	paginationLoop:true,
                        columns: [{
                            field: 'courtroom_name',
                            title: '法庭'
                        }, {
                            field: 'judge_name',
                            title: '法官'
                        },{
                            field: 'caseno',
                            title: '案件号'
                        }, {
                            field: 'casename',
                            title: '案件名称'
                        },{
                            field: 'summary',
                            title: '概要'
                        },{
                            field: 'start_date',
                            title: '开庭时间'
                        }
                        ],
                        data: result.data,
                        onClickRow:function (row) {
                            console.info(row);
                            Class.getCaseInfoById(row.plan_id,row.courtId);
                            Class.getCourtrecForId(row.plan_id,row.courtId);
                            if (row.status > 2) {
                                Class.getInfo(row.plan_id);
                            } else {
                                var court_ip = currentServerIP();
                                // Class.get_living_channel(row.plan_id,row.courtroom_id,court_ip);
                                getCgf(row.plan_id,row.courtroom_id,court_ip);
                            }
                        }
                    });
                    $('#table').bootstrapTable("load",result.data);
                    $('#table').bootstrapTable("hideLoading");

                }, 'json').fail(function () {
                    alert("查询失败");
                });
            }

        },
        getCaseInfoById:function(uid,cou) {
            $.ajax({
                url: r.base_path + "getCaseInfoByUid",
                type: "post",
                dataType: "json",
                data: {
                    uid: uid,
                    courtId: cou
                },
                success: function (result) {
                    if(result.status==1){
                        return ;
                    }
                    var caseInfo = result.data;
                    var caseNo = caseInfo.caseno;
                    var caseName = caseInfo.casename;
                    var subName = "";
                    var caseTypeName = caseInfo.casetype_name;
                    var judgeName = caseInfo.judge_id;
                    var secretaryName = caseInfo.secretary_id;
                    var courtroomName = caseInfo.courtroom_name;
                    var statusName = caseInfo.statusName;
                    var parties = caseInfo.accuse + " " + caseInfo.accused;
                    var startDate = caseInfo.start_date;
                    startDate = startDate.substring(0, startDate.length - 2);

                    var endDate = '未知';
                    if(caseInfo.end_date){
                        endDate = caseInfo.end_date.substring(0, caseInfo.end_date.length - 2);
                    }
                    var caseDesc = caseInfo.casedesc;
                    if (caseDesc == null) {
                        caseDesc = "";
                    }
                    console.log(result);
//		            $("#title").html('&nbsp;' + caseNo + "——" + caseName);
                    var html = ['  <div class="cmp-play-text">',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 案  号：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + caseNo + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>案件类型：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-8 text-left">',
                        '                                <span>' + caseTypeName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>案件名称：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + caseName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 审判长：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                                <span><a id="judge_name" class="white-a">' + (caseInfo.judge_name ? caseInfo.judge_name : '未知') + '</a></span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 书记员：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3  col-xs-8 text-left">',
                        '                                <span><a id="secretary_name" class="white-a">' + (caseInfo.secretary_name ? caseInfo.secretary_name : '未知') + '</a></span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>当事人：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + parties + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 开庭地点：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + (courtroomName?courtroomName:'未知') + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>开庭时间：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + startDate + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>闭庭时间：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + endDate + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span> 庭审状态：</span>',
                        '                            </div>',
                        '                            <div class="col-md-3 col-xs-8 text-left">',
                        '                                <span>' + statusName + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                        <div class="row row-court">',
                        '                            <div class="col-md-3 col-xs-4 text-right">',
                        '                                <span>   基本案情：</span>',
                        '                            </div>',
                        '                            <div class="col-md-9 col-xs-8 text-left">',
                        '                                <span>' + caseDesc + '</span>',
                        '                            </div>',
                        '                        </div>',
                        '                    </div>'].join("");
                    $("#center-tab-1").html("");
                    $("#center-tab-1").append(html);
//		            $("#judge_name").attr("href", r.base_path + encodeURI("views/more_reviewing.html?judge=" + judgeName + "&city=" + now_video+'&court='+r.court_id));
//           			$("#secretary_name").attr("href", r.base_path + encodeURI("views/more_reviewing.html?secretary=" + secretaryName + "&city=" + now_video+'&court='+r.court_id));
                }
            });
        },
        getCourtrecForId:function (planId,cou) {
            $.post(r.base_path + "courtrecForId", {planId: planId, courtId:cou}, function (result) {
                if (result && result.data) {
                    $("#center-tab-2").html(result.data[0]);
                    //绑定笔录下载地址--基于http下载
//		        	 $("#noteLoad").attr("href",result.data[1]);
                }
            });
        },
        getInfo:function(planId) {
            $.ajax({
                url: r.base_path + "playVideo",
                type: 'post',
                async: false,
                dataType: "json",
                data: {
                    planId: planId,
                    courtId:r.court_id
                },
                success: function (result) {
                    console.info(result);
                    if (result.status == 0) {
                        if (!result.data ||result.data.length==0) {
                            alert("没有找到点播信息！");
                            return;
                        }
                        //result.data赋值给_data 以后操作_data
                        p._data = result.data;
                        var chn = "";
                        //构造点播通道select
                        var video_row_1 = "";
                        var video_row_2 = "";
                        $.each(p._data, function (i, n) {
                            var filename = n.filename;
                            var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");

                            // console.log(sxs+n.chn);
                            if (chn.indexOf("[" + n.chn + sxs + "]") == -1) {
                                if( i < 4 ){
                                    video_row_1 += '<div class="col-md-3"><div class="group-left-dropdown" id="'+ n.channelsname +'">'
                                        +'        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
                                        +'			<div class="'+ sxs + n.chn +'" >'+ n.channelsname+'<span class="caret"></span></div></a> '
                                        +'        	<ul class="dropdown-menu"> '
                                        +'        	</ul> '
                                        +'  </div></div>';  //onclick=get_video_channel(this)
                                }else{
                                    video_row_2 += '<div class="col-md-3"><div class="group-left-dropdown" id="'+ n.channelsname +'">'
                                        +'        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
                                        +'			<div class="'+ sxs + n.chn +'" >'+ n.channelsname+'<span class="caret"></span></div></a> '
                                        +'        	<ul class="dropdown-menu"> '
                                        +'        	</ul> '
                                        +'  </div></div>';
                                }
                                chn += "[" + n.chn + sxs + "]";
                                p.now_channel_arr.push(sxs + n.chn);
                            }

                            var r = n.filename.match(/_\d+/g)[1].substr(1, 6);
                            n.time = r.substring(0, 2) + ":" + r.substring(2, 4);
                        });
                        $(".group-center-video-type").children("div:eq(0)").html("");
                        $(".group-center-video-type").children("div:eq(1)").html("");
                        $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
                        $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
                        initVideoSelect();
                        //初始化播放信道
                        if(p.now_channel_arr.length > 0){
                            p.now_channel = p.now_channel_arr[0];
                            get_video_channel(0);
                        }

//		                //获取url的点播通道号进行选中点播通道的select，如果为空则初始化
//		                if (channel == null && $("#channels>option").length != 0) {
//		                    channel = 1;
//		                } else {
//		                    $("#channels>option").eq(channel).attr("selected", "selected");
//		                }
//		                //调用方法进行构造点播录像select
//		                initVideoSelect();
//
//		                //尝试获取url中点播的视频编号进行选中点播录像select，如果为空则初始化
//
//		                if (!videoNum) {
//		                    videoNum = 0;	//无录像
//		                }
//		                $("#videos>option:eq(" + parseInt(videoNum) + ")").attr("selected", "selected");
//		                //根据点播录像构造vlc的播放列表
//		                initPlayList();
//
//		                //播放文件
//		                initdown(videoNum);

                    } else {
                        console.log(result.msg);
                    }
                }
            });
        },
        get_living_channel:function(plan_id,courtroom_id,court_ip){

        },
        init_verify_count:function () {
            var judge_list = [r.user_uuid];
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            $.get(r.base_path + 'major/findAllImagesCount', {
                courtId: r.court_id,
                userIds:JSON.stringify(judge_list),
                start:start_time,
                end:end_time,
                type:0
            }, function (result) {
                if(result.status == 1){
                    $("#right-list-tab-2").html("");
                    $("#right-list-tab-2").append('<span>无数据</span>');
                    return;
                }
                $("#right-list-tab-2").html("");

                $("#right-list-tab-2").append('<table id="table2" class="table table-bordered context-span context-white cursor-hand"></table>');
                $("#right-list-tab-2").append('<div id="_page2"></div>');

                var sum = result.data;
                if (sum == 0) {
                    page2(1, 1, null);
                } else {
                    page2(1, Math.ceil(sum / 5), Class.init_verify_page);
                }
                Class.init_verify_page(1);
            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        init_verify_page:function (page) {
            var judge_list = [r.user_uuid];
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            $.get(r.base_path + 'major/findAllImages', {
                courtId: r.court_id,
                userIds:JSON.stringify(judge_list),
                start:start_time,
                end:end_time,
                page:page,
                pageSize:5,
                type:0
            }, function (result) {
                $('#table2').bootstrapTable({
//			    	paginationLoop:true,
                    columns: [{
                        field: 'create_user',
                        title: '创建人'
                    },{
                        field: 'name',
                        title: '图片名称',
                        formatter: function (result,row) {
                            var date=new Date(row.create_time);
                            var type=row.type;
                            var url="http://"+location.hostname+":8080/";
                            if(type==1){
                                //图片
                                url=url+"images/";
                            }else{
                                //视频
                                url=url+"videos/";
                            }
                            url=url+date.getFullYear()+"/"+(date.getMonth() + 1)+"/"+result;
                            //拼接下载地址
                            var a="<a download class='btn btn-primary' href='"+url+"'>"+result+"</a>";
                            return a;
                        }
                    }, {
                        field: 'casename',
                        title: '案件名称'
                    },{
                        field: 'channelsame',
                        title: '通道名称'
                    },{
                        field: 'start_time',
                        title: '截取起点'
                    },{
                        field: 'end_time',
                        title: '截取终点'
                    },{
                        field: 'type',
                        title: '类型',
                        formatter: function (value) {
                            if (value==1){
                                return '图片'
                            }else if (value==2){
                                return '视频';
                            }else {
                                return '未知';
                            }

                        }
                    }],
                    data: result.data,
                    onClickRow:function (row) {
                    }
                });
                $('#table2').bootstrapTable("load",result.data);
                $('#table2').bootstrapTable("hideLoading");
            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        init_count_time:function(){
            //时间统计
            //获得时间月份数组
            var now = new Date();
            var month = now.getMonth()+1;
            var start_time = null;
            if(month >= 7){
                var start_month = month-6;
                start_time = now.getFullYear()+"-0"+start_month;
            }else{
                var start_month = 12+month-6;
                if (start_month < 10) {
                    start_time = now.getFullYear()-1+"-0"+start_month;
                }else {
                    start_time = now.getFullYear()-1+"-"+start_month;
                }
            }
            if (month < 10) {
                month = "0"+month;
            }
            var end_time = now.getFullYear()+"-"+month;
            var time_arr = [start_time];
            for(var i=0;i<5;i++){
                var last_month = parseInt(time_arr[time_arr.length-1].substr(5));
                if(last_month<12){
                    var temp_month = last_month+1;
                    if(temp_month<10){
                        time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-0"+temp_month);
                    }else{
                        time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-"+temp_month);
                    }
                }else if(last_month == 12){
                    time_arr.push(parseInt(time_arr[time_arr.length-1].substr(0,4))+1+"-01");
                }
            }
            time_arr.push(end_time);
       	// console.info(time_arr);
            $.get(r.base_path + 'findListJudgeMonthStatistics', {
                startDate:start_time,
                endDate: end_time,
                judgeList:r.user_uuid.toString()
            }, function (result) {
                var ydata = [];
                for(var i=0;i<time_arr.length;i++){
                    ydata[i] = 0 ;
                    $.each(result.data,function(index,elem){
                        if(time_arr[i] == elem.date){
                            ydata[i] = elem.trialtime ;
                        }
                    });
                }
                var myChart = echarts.init(document.getElementById('right-chart-tab-1'), "shine");
                // 指定图表的配置项和数据
                var option = {
//				    		title: {
//				    			text: "开庭数统计(次)", //正标题
//				    			x: "left", //标题水平方向位置
//				    			textStyle: {
//				    				fontSize:24,
//				    				color:"#FFFFFF"
//				    				}
//				    		},
                    color: ['#D5B136'],
                    /* title:{
                     text:title,
                     textStyle:{
                     color:"#ffffff"
                     }
                     },*/
                    grid: {
                        show: false,
                        left: '9%',
                        right: '6%',
                        top: 30,
                        bottom: 30
                    },
                    tooltip: {},
                    xAxis: {
                        data: time_arr,
                        axisLine: {
                            lineStyle: {
                                color: "#1c4e93"
                            }
                        },
                        axisLabel: {
                            textStyle: {
                                fontSize:16,
                                color: "#FFFFFF"
                            },
                            // rotate:-30,
                            interval:0
                        }
                    },
                    yAxis: {
                        axisLine: {
                            lineStyle: {
                                color: "#1c4e93"
                            }
                        },
                        axisLabel: {
                            textStyle: {
                                fontSize:16,
                                color: "#FFFFFF"
                            },
                            formatter: function (value) {
                                return value + 'h'
                            }
                        }
                    },
                    series: [{
                        name: '开庭时长',
                        //            barWidth: '50%',
                        barMaxWidth:20,
                        type: 'bar',
                        itemStyle:{
                            normal:{
                                label:{
                                    show:true,
                                    position:'top',
                                    textStyle: {
                                        color: "#d94600",
                                        fontSize:20
                                    }
                                }
                            }
                        },
                        data: ydata
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                window.onresize = myChart.resize;

            }, 'json').fail(function () {
                alert("查询失败");
            });

        },
        init_judge_ranking:function(){
            //时间统计
                //获得时间月份数组
                var now = new Date();
                var month = now.getMonth()+1;
                var start_time = null;
                if(month >= 7){
                    var start_month = month-6;
                    start_time = now.getFullYear()+"-0"+start_month;
                }else{
                    var start_month = 12+month-6;
                    if (start_month < 10) {
                        start_time = now.getFullYear()-1+"-0"+start_month;
                    }else {
                        start_time = now.getFullYear()-1+"-"+start_month;
                    }
                }
                if (month < 10) {
                    month = "0"+month;
                }
                var end_time = now.getFullYear()+"-"+month;
                var time_arr = [start_time];
                for(var i=0;i<5;i++){
                    var last_month = parseInt(time_arr[time_arr.length-1].substr(5));
                    if(last_month<12){
                        var temp_month = last_month+1;
                        if(temp_month<10){
                            time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-0"+temp_month);
                        }else{
                            time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-"+temp_month);
                        }
                    }else if(last_month == 12){
                        time_arr.push(parseInt(time_arr[time_arr.length-1].substr(0,4))+1+"-01");
                    }
                }
                time_arr.push(end_time);
                // console.info(time_arr);
                $.get(r.base_path + 'findListJudgeMonthStatistics', {
                    startDate:start_time,
                    endDate: end_time,
                    judgeList:r.user_uuid.toString()
                }, function (result) {
                    var ydata = [];
                    for(var i=0;i<time_arr.length;i++){
                        ydata[i] = 0 ;
                        $.each(result.data,function(index,elem){
                            if(time_arr[i] == elem.date){
                                ydata[i] = elem.trialnum ;
                            }
                        });
                    }
                    // 指定图表的配置项和数据
                    var option = {
//				    		title: {
//				    			text: "开庭数统计(次)", //正标题
//				    			x: "left", //标题水平方向位置
//				    			textStyle: {
//				    				fontSize:24,
//				    				color:"#FFFFFF"
//				    				}
//				    		},
                        color: ['#D5B136'],
                        /* title:{
                         text:title,
                         textStyle:{
                         color:"#ffffff"
                         }
                         },*/
                        grid: {
                            show: false,
                            left: '9%',
                            right: '6%',
                            top: 30,
                            bottom: 30
                        },
                        tooltip: {},
                        xAxis: {
                            data: time_arr,
                            axisLine: {
                                lineStyle: {
                                    color: "#1c4e93"
                                }
                            },
                            axisLabel: {
                                textStyle: {
                                    fontSize:16,
                                    color: "#FFFFFF"
                                },
                                // rotate:-30,
                                interval:0
                            }
                        },
                        yAxis: {
                            axisLine: {
                                lineStyle: {
                                    color: "#1c4e93"
                                }
                            },
                            axisLabel: {
                                textStyle: {
                                    fontSize:16,
                                    color: "#FFFFFF"
                                },
                                formatter: function (value) {
                                    return value + '次'
                                }
                            }
                        },
                        series: [{
                            name: '开庭次数',
                            //            barWidth: '50%',
                            barMaxWidth:20,
                            type: 'bar',
                            itemStyle:{
                                normal:{
                                    label:{
                                        show:true,
                                        position:'top',
                                        textStyle: {
                                            color: "#d94600",
                                            fontSize:20
                                        }
                                    }
                                }
                            },
                            data: ydata
                        }]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    ready.right_chart_tab_2.setOption(option);
                    window.onresize = ready.right_chart_tab_2.resize;

                }, 'json').fail(function () {
                    alert("查询失败");
                });

        },
        convert_data: function (data) {
            // console.log(typeof data,data);
            var res = [];
            $(data).each(function (index, elem) {
                res.push({
                    name: elem.courtName,
                    value: [parseFloat(elem.lng), parseFloat(elem.lat), elem.total, elem.courtId],
                    color: '#FF7F50',
                    itemStyle: {
                        normal: {
                            textStyle: {
                                fontSize: 16,
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        },
                        emphasis: {
                            textStyle: {
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        }
                    }
                });
            });
            // console.log(res);
            return res;
        }

    };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {
        // judge_change: Class.judge_change,
        // courtroom_change: Class.courtroom_change,
        _data:null,
        pro_bar:ready.pro_bar,
        now_channel:null,//记录当前播放的信道
        now_channel_arr:[]
    };
}(window);


function page(now, totalPages, callback) {
    base.pagination('#_page', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}
function page2(now, totalPages, callback) {
    base.pagination('#_page2', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}

// JS VLC API callbacks
function handleMediaPlayerMediaChanged() {
    console.log('media change');
}

function handle_MediaPlayerNothingSpecial() {
    // document.getElementById("state").innerHTML = "Idle...";
}

function handle_MediaPlayerOpening() {
    // onOpen();
}

function handle_MediaPlayerBuffering(val) {
    // document.getElementById("info").innerHTML = val + "%";
}

function handle_MediaPlayerPlaying() {
    onPlaying();
}

function handle_MediaPlayerPaused() {
    onPause();
}

function handle_MediaPlayerStopped() {
//     onStop();
}

function handle_MediaPlayerForward() {
    // document.getElementById("state").innerHTML = "Forward...";
}

function handle_MediaPlayerBackward() {
    // document.getElementById("state").innerHTML = "Backward...";
}

function handle_MediaPlayerEndReached() {
    // onEnd();
}

function handle_MediaPlayerEncounteredError() {
    // onError();
}

function handle_MediaPlayerPositionChanged(val) {
    // set javascript slider to correct position
}

function handle_MediaPlayerSeekableChanged(val) {
    // setSeekable(val);
}

function handle_MediaPlayerPausableChanged(val) {
    // setPauseable(val);
}

function handle_MediaPlayerTitleChanged(val) {
    //setTitle(val);
    document.getElementById("info").innerHTML = "Title: " + val;
}

function handle_MediaPlayerLengthChanged(val) {
    //setMediaLength(val);
}


function doSetSlider(time) {
    var vlc = getVLC("vlc");
    if (vlc) {
        doPlayOrPause();
//        vlc.input.time = (time);
        window.setTimeout(doPlayOrPause, 500);
    }
}


function doPlayOrPause() {
    var vlc = getVLC("vlc");
    if (vlc) {
        vlc.playlist.togglePause();
    }
}

function onPlaying(){
    var vlc = getVLC("vlc");
    if( vlc ) {
        var mediaLen = vlc.input.length;
        if (mediaLen>0){
            p.pro_bar.loadeddata(mediaLen,1);//加载的视频长度60秒 以50%的音量播放
            // audio.audioPlayer({
            //     duration:(mediaLen/1000)
            // });
        }
    }
}

function onPause() {
}

function formatTime(timeVal) {
    if( typeof timeVal != 'number' )
        return "-:--:--";

    var timeHour = Math.round(timeVal / 1000);
    var timeSec = timeHour % 60;
    if( timeSec < 10 )
        timeSec = '0'+timeSec;
    timeHour = (timeHour - timeSec)/60;
    var timeMin = timeHour % 60;
    if( timeMin < 10 )
        timeMin = '0'+timeMin;
    timeHour = (timeHour - timeMin)/60;
    if( timeHour > 0 )
        return timeHour+":"+timeMin+":"+timeSec;
    else
        return timeMin+":"+timeSec;
}

function getVLC(name) {
    if (window.document[name]) {
        return window.document[name];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[name])
            return document.embeds[name];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(name);
    }
}

// VLC Plugin
function onVLCPluginReady() {
    registerVLCEvent("MediaPlayerMediaChanged", handleMediaPlayerMediaChanged);
    registerVLCEvent("MediaPlayerNothingSpecial", handle_MediaPlayerNothingSpecial);
    registerVLCEvent("MediaPlayerOpening", handle_MediaPlayerOpening);
    registerVLCEvent("MediaPlayerBuffering", handle_MediaPlayerBuffering);
    registerVLCEvent("MediaPlayerPlaying", handle_MediaPlayerPlaying);
    registerVLCEvent("MediaPlayerPaused", handle_MediaPlayerPaused);
    registerVLCEvent("MediaPlayerStopped", handle_MediaPlayerStopped);
    registerVLCEvent("MediaPlayerForward", handle_MediaPlayerForward);
    registerVLCEvent("MediaPlayerBackward", handle_MediaPlayerBackward);
    registerVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached);
    registerVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError);
    registerVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged);
    registerVLCEvent("MediaPlayerPositionChanged", handle_MediaPlayerPositionChanged);
    registerVLCEvent("MediaPlayerSeekableChanged", handle_MediaPlayerSeekableChanged);
    registerVLCEvent("MediaPlayerPausableChanged", handle_MediaPlayerPausableChanged);
    registerVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged);
    registerVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged);
}

function close(){
    unregisterVLCEvent("MediaPlayerMediaChanged", handleMediaPlayerMediaChanged);
    unregisterVLCEvent("MediaPlayerNothingSpecial", handle_MediaPlayerNothingSpecial);
    unregisterVLCEvent("MediaPlayerOpening", handle_MediaPlayerOpening);
    unregisterVLCEvent("MediaPlayerBuffering", handle_MediaPlayerBuffering);
    unregisterVLCEvent("MediaPlayerPlaying", handle_MediaPlayerPlaying);
    unregisterVLCEvent("MediaPlayerPaused", handle_MediaPlayerPaused);
    unregisterVLCEvent("MediaPlayerStopped", handle_MediaPlayerStopped);
    unregisterVLCEvent("MediaPlayerForward", handle_MediaPlayerForward);
    unregisterVLCEvent("MediaPlayerBackward", handle_MediaPlayerBackward);
    unregisterVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached);
    unregisterVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError);
    unregisterVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged);
    unregisterVLCEvent("MediaPlayerPositionChanged", handle_MediaPlayerPositionChanged);
    unregisterVLCEvent("MediaPlayerSeekableChanged", handle_MediaPlayerSeekableChanged);
    unregisterVLCEvent("MediaPlayerPausableChanged", handle_MediaPlayerPausableChanged);
    unregisterVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged);
    unregisterVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged);
}

function registerVLCEvent(event, handler) {
    var vlc = getVLC("vlc");
    if (vlc) {
        if (vlc.attachEvent) {
            // Microsoft
            vlc.attachEvent(event, handler);
        } else if (vlc.addEventListener) {
            // Mozilla: DOM level 2
            vlc.addEventListener(event, handler, true);
        } else {
            // DOM level 0
            eval("vlc.on" + event + " = handler");
        }
    }
}

function unregisterVLCEvent(event, handler) {
    var vlc = getVLC("vlc");

    if (vlc) {
        if (vlc.detachEvent) {
            // Microsoft
            vlc.detachEvent(event, handler);
        } else if (vlc.removeEventListener) {
            // Mozilla: DOM level 2
            vlc.removeEventListener(event, handler, true);
        } else {
            // DOM level 0
            eval("vlc.on" + event + " = null");
        }
    }
}

//更新正在播放的时间
function handle_MediaPlayerTimeChanged(time) {
    var vlc = getVLC("vlc");
    if (vlc) {
        var mediaLen = vlc.input.length;
        if (mediaLen > 0) {
            //audio.time_update(time/1000)
        }
    }
}

function get_video_channel(vlcItem){
    vlcItem = vlcItem ? vlcItem : 0;
//	var channel = $(val).attr('class');
//	if(!channel){
//		channel = val;
//	}
//	console.info(channel);
//	if(channel == p.now_channel){
//		return;
//	}else{
//		p.now_channel = channel;
    var vlc = getVLC("vlc");
    if (vlc) {
        //一言不合先清除下播放列表
        vlc.playlist.items.clear();
        //防止出现意外时初始化视频号
        $.each(p._data, function (i, n) {
            var options = [":vout-filter=deinterlace", ":deinterlace-mode=linear"];
            var filename = n.filename;
            var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");

            var temp = p.now_channel;
            //              console.log(sxs+n.chn + channel,"----sxs",sxs+n.chn,"----temp",temp);
            if (sxs + n.chn == temp) {
//	                vlc.playlist.add("http://" + n.url + ":8200/" + n.filename, "", options);
                    vlc.playlist.add("http://" + n.url + ":8200/" + n.filename, "", options);
                options = [];
            }
        });
        vlc.playlist.playItem(vlcItem);
    }
//	}
}

function initVideoSelect() {
    $.each(p._data, function (j, n) {
        var filename = n.filename;
        var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");
        var now_name = n.channelsname;
        var temp_channel = sxs + n.chn;
        if(j < p._data.length-1 ){
            if(now_name == p._data[j+1].channelsname){
                $("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time+'--'+p._data[j+1].time +'</a></li>');
            }else{
                $("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time +'</a></li>');
            }
        }else{
            $("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time +'</a></li>');
        }
    });
}
function select_video_channel(val){
    p.now_channel = $(val).attr("class");
    var vlcItem = $(val).parents("li").parents("ul").find("li").index($(val).parents("li"));
//	console.info(p.now_channel,"   ",vlcItem);
    get_video_channel(vlcItem);
}

function currentServerIP() {
    var ip = '';
    $.ajax({
        url: r.base_path + "currentServerIP",
        type: 'post',
        async: false,
        dataType: "text",
        success: function (result) {
            ip = result;
        }
    });
    return ip;
}

function getCgf(uid, cid, courtIp,channel) {
    channel = channel?channel:1;
    $(".group-center-video-type").children("div:eq(0)").html("");
    $(".group-center-video-type").children("div:eq(1)").html("");
    $.ajax({
        url: r.base_path + "sys/courtSetting/getCfgInfo",
        type: "post",
        dataType: "json",
        data: {
            cId: cid,
            index: channel,
            ip: courtIp
        },
        success: function (result) {
            if (result != null) {
                var data = result.data;
                var count = 0;
                var video_row_1 = "";
                var video_row_2 = "";

                for (var key in  data) {
                    if( count < 4 ){
                        video_row_1 += '<div class="col-md-3"><div>'+key+'</div></div>';  //onclick=get_video_channel(this)
                    }else{
                        video_row_2 += '<div class="col-md-3"><div>'+key+'</div></div>';
                    }
                    count = count + 1;
                }
                $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
                $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
                //初始化直播信号
                $(".group-center-video-type").find(".col-md-3").eq(channel - 1).find("div").attr("class","active");
                var d = $(".group-center-video-type").find(".col-md-3").eq(channel - 1).find("div").html();
                var cha = data[d];//默认显示
                initialise(courtIp, cha);
                console.log(data,d,cha);
                $(".group-center-video-type").children("div").children('div').click(function () {
                    var inx = $(".group-center-video-type").find(".col-md-3").index(this) + 1;
                    console.info(inx);
                    getCgf(uid, cid, courtIp,inx);
                });
            }

        },
        error: function () {
        }
    });
}

function initialise(courtIp, cfg) {
    var vlc = getVLC("vlc");
    console.log(vlc,'vlcccccc')
    if (vlc) {
        vlc.playlist.items.clear();
        while (vlc.playlist.items.count > 0) {
            // clear() may return before the playlist has actually been cleared
            // just wait for it to finish its job
        }
        var options = [":rtsp-tcp"];
        var itemId;
        console.log("rtsp://" + courtIp + "/" + cfg);
        itemId = vlc.playlist.add("rtsp://" + courtIp + "/" + cfg, "", options);

        if (itemId != -1) {
            vlc.playlist.playItem(itemId);
        }else {
            alert("cannot play at the moment !");
        }
    }
}
